<?php
	include_once 'autoload.php';
	
	session_start();

	$ctl = new AlbumsCtl();
	$ctl->checkLogged();
	$ctl->proceed();
	
	$logged = HtmlUtil::getSessionUser();
	$readonly = $logged->isReadonly();
	
	$header = new Header();
	$header->render('Albums');

	$form = $ctl->getAlbumsForm();

	$search = $form->getSearch();
	$albums = $form->getAlbums();
	$selected = $form->getSelected();
	
	$control = new AlbumListControl();
	$rendered = $control->render(4, $albums, $selected, $readonly);
	
?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="pagename" value="albums" id="pgid">
<input type="hidden" name="metname" value="" id="metid">
<input type="hidden" name="idedit" value="" id="idedit">

<h2>Albums</h2>
<p>Search for albums; then click on one of the 
albums in the search results to see the enclosed pictures</p>
<table cellspacing="0" cellpadding="4" style="margin-bottom: 10px;">
  <tr>
    <td valign="middle">Search: 
      <input name="search" type="text" value="<?php echo $search; ?>">
      <input type="button" value="Search" onclick="triggerform('search')" class="enter">
    </td>
  </tr>
</table>

<?php echo $rendered; ?>

<table cellspacing="0" cellpadding="8" style="margin-top:10px;">
  <tr>
    <td nowrap>
    <?php 
    	if(! $readonly) {
    ?>
	    <input type="button" value="Add" onclick="triggerform('add')">
	    <input type="button" value="Delete" onclick="triggerform('delete')">
	<?php 
    	}
	    else {
	    	echo "&nbsp;";
	    }
	?>
    </td>
  </tr>
</table>
</form>
<?php
	$footer = new Footer();
	$footer->render();
?>
